package guicemodules;

import static com.google.common.base.Throwables.propagate;

import java.io.IOException;
import java.nio.file.Paths;

import archivemanagement.LibraryArchive;
import archivemanagement.OperatorArchive;
import archivemanagement.OperatorDescriptionArchive;
import archivemanagement.SpecArchive;
import archivemanagement.TypeArchive;
import archivemanagement.ZippedArchive;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;

public class ZippedArchiveModule extends AbstractModule {
    
    @Override
    protected void configure()
    {
        
        bind(TypeArchive.class).to(ZippedArchive.class);
        bind(TypeArchive[].class).to(ZippedArchive[].class);
        
        bind(OperatorArchive.class).to(ZippedArchive.class);
        bind(OperatorArchive[].class).to(ZippedArchive[].class);
        
        bind(OperatorDescriptionArchive.class).to(ZippedArchive.class);
        bind(OperatorDescriptionArchive[].class).to(ZippedArchive[].class);
        
        bind(SpecArchive.class).to(ZippedArchive.class);
        bind(SpecArchive[].class).to(ZippedArchive[].class);
        
        bind(LibraryArchive.class).to(ZippedArchive.class);
        bind(LibraryArchive[].class).to(ZippedArchive[].class);
    }
    
    @Provides
    private ZippedArchive provideDefaultZippedLibrary()
    {
        try {
            return new ZippedArchive(Paths.get(""), "lib");
        }
        catch(IOException e) {
            throw propagate(e);
        }
    }
    
    @Provides
    private ZippedArchive[] provideZippedLibraries()
    {
        return new ZippedArchive[] { provideDefaultZippedLibrary() };
    }
}
